package cn.jinjimi.app.main.activity;

import android.content.Intent;
import android.net.Uri;
import android.support.v4.content.ContextCompat;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;

import com.facebook.common.util.UriUtil;
import cn.jinjimi.base.util.GsonUtils;
import cn.jinjimi.app.R;
import cn.jinjimi.domain.data.net.ApiConstants;
import cn.jinjimi.app.controller.event.DataEvent;
import cn.jinjimi.app.controller.event.HonorAddEvent;
import cn.jinjimi.app.entity.HonorBean;
import cn.jinjimi.app.main.extend.ToolBarCommonActivity;
import cn.jinjimi.app.util.PhotoUtils;
import cn.jinjimi.app.util.UploadPhotosUtil;

import org.greenrobot.eventbus.EventBus;

/**
 * Created by Roy
 * Date: 15/9/6
 */
public class PersonalHonorPostActivity extends ToolBarCommonActivity {

    public final static String IMAGE_PATH = "iamge_path";

    private EditText edHonorName;
    private ImageView img;

    private String path;

    @Override
    protected void beforeInitView() {
        setContentView(R.layout.activity_honor_post_layout);
        setTitle(getString(R.string.info_honor));
        setRightText(R.string.save);
    }

    @Override
    protected void initial() {
        initView();
        initListener();
        initData();
    }

    protected void initView() {
        edHonorName = (EditText) findViewById(R.id.et_name);
        img = (ImageView) findViewById(R.id.img);
    }

    protected void initListener() {
        img.setOnClickListener(this);
    }

    protected void initData() {
        path = getIntent().getStringExtra(IMAGE_PATH);
        Uri uri = new Uri.Builder()
                .scheme(UriUtil.LOCAL_FILE_SCHEME)
                .path(path)
                .build();
        img.setImageURI(uri);
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.img:
                PhotoUtils.pickPhoto(PersonalHonorPostActivity.this, true, 3 / 4f);
                break;
        }
    }

    @Override
    protected void rightAction() {
        super.rightAction();
        if (path != null) {
            if (TextUtils.isEmpty(edHonorName.getText().toString().trim())) {
                edHonorName.setHintTextColor(ContextCompat.getColor(PersonalHonorPostActivity.this, R.color.red_dark));
            } else {
                upLoadHonor();
            }
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        path = PhotoUtils.handlePhotoResult(this, data, requestCode, resultCode);
        if (path != null) {
            Uri uri = new Uri.Builder()
                    .scheme(UriUtil.LOCAL_FILE_SCHEME)
                    .path(path)
                    .build();
            img.setImageURI(uri);
        }
    }

    private void upLoadHonor() {

    }
}
